package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description NursingProjectController
 * @Author wangxinyi
 * @Date 2024-10-15
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;


    /**
     * 分页查询
     *
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "当前页码") Integer pageNum,
            @ApiParam(value = "每页显示条数") Integer pageSize,
            @ApiParam(value = "状态 0：禁用，1：启用") Integer status) {

        //调用
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    /**
     * 新增护理项目
     *
     * @param dto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult<String> add(
            @ApiParam(value = "护理项目数据传输对象", required = true) @RequestBody NursingProjectDto dto) {
        nursingProjectService.add(dto);
        return success();
    }

    /**
     * 根据id查询护理项目
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> selectById(@ApiParam(value = "id参数", required = true) @PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return success(nursingProjectVo);
    }

    /**
     * 编辑护理项目
     */
    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult<String> update(@ApiParam("护理项目传输数据对象") @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }
}
